import React, { Component } from 'react';
import { Tabs } from 'antd';
import { ContentPackage, TabC } from '../../../comps';
import TabSearch from './TabSearch';

const { TabPane } = Tabs;

export default class index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      activeKey: '1',
      colType: 'Implied_Rating_1', // 中债查询的列
    };
  }

  componentDidMount() {
    // 适配用户视图跳转至债券评级监控
    if (sessionStorage.getItem('jumpInfo') != null) {
      const obj = JSON.parse(sessionStorage.getItem('jumpInfo'));
      if (obj.type == '12') {
        this.setState(
          {
            activeKey: obj.activeKey,
          },
          () => {
            this.myChild2.refresh(obj.securityCode, obj.securityName);
          },
        );
        sessionStorage.removeItem('jumpInfo');
      }
    }
  }

  UNSAFE_componentWillReceiveProps(nextProps) {
    if (sessionStorage.getItem('jumpInfo') != null) {
      const obj = JSON.parse(sessionStorage.getItem('jumpInfo'));
      if (obj.type == '12') {
        this.setState(
          {
            activeKey: obj.activeKey,
          },
          () => {
            this.myChild2.refresh(obj.securityCode, obj.securityName);
          },
        );
        sessionStorage.removeItem('jumpInfo');
      }
    }
  }

  onChange = (activeKey) => {
    this.setState({
      activeKey,
    });
  };

  render() {
    return (
      <ContentPackage
        title='债券评级监控'
        contentHtml={
          <div className='monitorRating'>
            <TabC
              tabSource={[
                {
                  title: '主体评级监控',
                  key: '1',
                  content: (
                    <TabSearch
                      type={'0'}
                      onRef={(ref) => {
                        this.myChild1 = ref;
                      }}
                      isReset={false}
                    />
                  ),
                },
                {
                  title: '债券评级监控',
                  key: '2',
                  content: (
                    <TabSearch
                      type={'1'}
                      onRef={(ref) => {
                        this.myChild2 = ref;
                      }}
                      isReset={false}
                    />
                  ),
                },
                {
                  title: '中债隐含评级监控',
                  key: '3',
                  content: (
                    <TabSearch
                      type={'2'}
                      colType={this.state.colType}
                      onRef={(ref) => {
                        this.myChild3 = ref;
                      }}
                      isReset={false}
                      changeCol={(e) => {
                        this.setState({ colType: e });
                      }}
                    />
                  ),
                },
              ]}
              activeKey={this.state.activeKey}
              onChange={this.onChange}
            />
          </div>
        }
      />
    );
  }
}
